package com.tracking.locon;

import java.util.ArrayList;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.drawable.Drawable;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

/*
 * Source: https://developers.google.com/maps/documentation/android/hello-mapview
 */
public class TrackItemizedOverlay extends ItemizedOverlay<OverlayItem> {
	private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
	Context mContext;

	public TrackItemizedOverlay(Drawable marker) {
		super(boundCenter(marker));
	}

	public TrackItemizedOverlay(Drawable marker, Context context) {
		//super(boundCenterBottom(marker));
		this(marker);
		mContext = context;
	}

	public void addOverlay(OverlayItem overlay) {
		mOverlays.add(overlay);
		populate();
	}

	@Override
	protected OverlayItem createItem(int i) {
		return mOverlays.get(i);
	}

	@Override
	public int size() {
		return mOverlays.size();
	}
	
	@Override
	protected boolean onTap(int i) {
		// when you tap on the marker this will show the informations provided
		// by you when you create in the
		// main class the OverlayItem
		OverlayItem item = mOverlays.get(i);
		AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
		builder.setTitle(item.getTitle())
				.setCancelable(true)
				.setPositiveButton("Chat", new DialogInterface.OnClickListener() {
					
					public void onClick(DialogInterface dialog, int which) {
						//http://stackoverflow.com/questions/4448427/can-i-personalize-the-ontap-dialog-of-the-items-on-my-googlemapview-i-wanna
						// TODO
						
					}
				});
		/*
				.setNegativeButton("Close", new DialogInterface.OnClickListener() {
					
					public void onClick(DialogInterface dialog, int which) {
						// TODO
						
					}
				});*/
		AlertDialog alert = builder.create();
		alert.show();
		return true;
		/*
		OverlayItem item = g_Overlays.get(i);
		AlertDialog.Builder dialog = new AlertDialog.Builder(g_Context);
		dialog.setTitle(item.getTitle());
		dialog.setMessage(item.getSnippet());
		dialog.show();
		return true;
		*/
	}
}
